package com.coocaa.ops.admin.v1.plugin.util;

import com.coocaa.ops.admin.v1.plugin.model.output.PluginInfoModel;
import com.coocaa.ops.common.core.biz.plugin.entity.PluginInfoEntity;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author tangminghong
 * @date 2020-07-21
 */
public class PluginInfoConverter {

    public static List<PluginInfoModel> convertToModel(List<PluginInfoEntity> entitylist) {
        if (CollectionUtils.isEmpty(entitylist)) {
            return Collections.emptyList();
        }
        List<PluginInfoModel> pluginModelList = new ArrayList<>(entitylist.size());

        for (PluginInfoEntity pluginEntity : entitylist) {
            PluginInfoModel pluginModel = new PluginInfoModel();
            BeanUtils.copyProperties(pluginEntity, pluginModel);
            pluginModel.setHomeVersion(Objects.toString(pluginEntity.getHomeVersion()));
            pluginModel.setPluginVersion(Objects.toString(pluginEntity.getPluginVersion()));
            pluginModelList.add(pluginModel);
        }
        return pluginModelList;
    }
}
